package cn.jn.lhm.acl.handler;

import cn.jn.lhm.acl.entity.Permission;
import cn.jn.lhm.acl.service.PermissionService;
import cn.jn.lhm.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author LHM
 * @Tips 热爱每一天，奋斗每一天
 * @date 2020/6/22 - 20:23
 */
@RestController
@RequestMapping("/acl/per")
public class PermissionHandler {

    @Resource
    private PermissionService permissionService;

    @ApiOperation(value = "递归查询所有菜单")
    @GetMapping("/getAll")
    public R getAllPermission() {
        List<Permission> list = permissionService.getAllInfo();
        return R.ok().data("data", list);
    }

    @ApiOperation(value = "递归删除某一个菜单")
    @DeleteMapping("/delete/{id}")
    public R deletePermissionById(@PathVariable("id")String id){
        permissionService.deletePermissionById(id);
        return R.ok();
    }

    @ApiOperation(value = "给角色分配权限")
    @PostMapping("/ad/assign")
    public R doAssign(String roleId, String[] permissionId){
        permissionService.doAssign(roleId, permissionId);
        return R.ok();
    }

}
